package com.matt.controller.pad;

import com.matt.commons.dto.sso.StaffDTO;;
import com.matt.commons.model.StatusResponse;
import com.matt.domain.comment.Comment;
import com.matt.domain.comment.ExtCommentsSupport;
import com.matt.foundation.model.MemVerificationCache;
import com.matt.commons.page.PagerQuery;
import com.matt.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static com.matt.foundation.constant.RequestConstant.TICKET;


/**
 * @Describle This Class Is
 * @Author ZengMin
 * @Date 2018/11/7 10:08
 * @Company Matt
 */
@RequestMapping("/pad/comments")
@RestController
public class PadCommentsController {

    @Autowired
    private MemVerificationCache cache;

    @Autowired
    private CommentsService commentsService;

    @RequestMapping(value = "/all", method = RequestMethod.GET)
    @ResponseBody
    public StatusResponse getCommentsList(HttpServletRequest req, HttpServletResponse resp,
                                          @RequestHeader(TICKET) String ticket,
                                          String resId, int resType,
                                          PagerQuery pagerQuery) {

        StaffDTO baseInfo = cache.getStaff(ticket);

        ExtCommentsSupport exto = commentsService.commentHostForResIdAndResType(resId, resType);

        return StatusResponse.success(exto);
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public StatusResponse postComment(HttpServletRequest req, HttpServletResponse resp,
                                      @RequestHeader(TICKET) String ticket,
                                      String resId, int resType,
                                      String content, String refCommentId) {

        StaffDTO baseInfo = cache.getStaff(ticket);
        String areaId = baseInfo.getAreaId();
        String staffId = baseInfo.getId();
        String staffName = baseInfo.getRealName();

        Comment comment = commentsService.addCommentForResIdAndResType(staffId, staffName, resId, resType, content, refCommentId);

        return StatusResponse.success(comment);
    }


}
